package com.qf.fmmall.service.impl;

import com.qf.fmmall.dao.CategoryMapper;
import com.qf.fmmall.entity.CategoryVo;
import com.qf.fmmall.service.CategoryService;
import com.qf.fmmall.vo.ResStatus;
import com.qf.fmmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public ResultVo listCategories() {
        ResultVo vo = new ResultVo();
        List<CategoryVo> categoryVOS = categoryMapper.selectAllCategories();
        if (categoryVOS.size() == 0 ){
            vo.setCode(ResStatus.NO);
            vo.setMsg("没有查到分类数据");
        }else {
            vo.setCode(ResStatus.OK);
            vo.setMsg("success");
            vo.setData(categoryVOS);
        }
        return vo;
    }
}
